package cz.cuni.amis.episodic.bayes.utils.chart;

import java.awt.Color;
import java.awt.Paint;
import org.jfree.chart.plot.GreyPalette;
import org.jfree.chart.renderer.GrayPaintScale;

/**
 *
 * @author ik
 */
public class ColorScaleRenderer extends GrayPaintScale {

    protected final Color nan = Color.RED;

    public ColorScaleRenderer(double lowerBound, double upperBound) {
        super(lowerBound, upperBound);
    }

    public ColorScaleRenderer(double lowerBound, double upperBound, int alpha) {
        super(lowerBound, upperBound, alpha);
    }

    public Paint getPaint(double value) {
        if (Double.isNaN(value)) {
            return new Color(255, 0, 0, getAlpha());
        }
        double v = Math.max(value, this.getLowerBound());
        v = Math.min(v, this.getUpperBound());
        int g = 255 - (int) ((v - this.getLowerBound()) / (this.getUpperBound()
                - this.getLowerBound()) * 255.0);
        // FIXME:  it probably makes sense to allocate an array of 256 Colors
        // and lazily populate this array...
        return new Color(g, g, g, this.getAlpha());
    }
}
